<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/header.jsp" %>


<div class="row">
	<div class="col-xs-12">	
		<form id="detailForm" name="detailForm" class="form-horizontal" role="form">
			 <div class="row">
			<!--	<div class="alert alert-info col-sm-12">
					<button type="button" class="close" data-dismiss="alert">
						<i class="ace-icon fa fa-times"></i>
					</button>
				<strong>注: </strong>
				&nbsp;所属机构、参数主键为空时将默认为*号
				<br />
			</div> -->
			</div>
			<div class="row">
				<div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="paramType">参数类型 </label>
					<div class="col-sm-9">
						<input type="text" class="col-xs-10 col-sm-8"  name="paramType" id="paramType" value="${paramInfo.paramType}" disabled />
					</div>
				</div>
				<div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="paramName">参数名称 </label>
					<div class="col-sm-9">
						<input type="text" class="col-xs-10 col-sm-8"  name="paramName" id="paramName" value="<hw:dictName dictType='D00021' dictCode='${paramInfo.paramType}' />" disabled />
					</div>
				</div>
				<div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="_orgId">所属机构 <font color="red">*</font></label>
					<div class="col-sm-9">
						<div class="clearfix">
							<input type="text" class="col-xs-10 col-sm-8 " id="orgId" name="orgId"  value="${paramInfo.orgId}" />
						</div>
					</div>
				</div>	
				<div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="paramKey">参数主键 <font color="red">*</font></label>
					<div class="col-sm-9">
						<div class="clearfix">
							<input type="text" class="col-xs-10 col-sm-8"  id="paramKey" name="paramKey" value="${paramInfo.paramKey}" maxlength="20" disabled />
						</div>
					</div>
				</div>
				<hr />			
				<div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="param1"> ${columnNames['param1']}</label>
					<div class="col-sm-9">
						<div class="clearfix">
							<input type="text" class="col-xs-10 col-sm-8 can-modify"  id="param1" name="param1" value="${paramInfo.param1}" maxlength="20" />
						</div>
					</div>
				</div>						
				<div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="param2"> ${columnNames['param2']}</label>
					<div class="col-sm-9">
						<div class="clearfix">
							<input type="text" class="col-xs-10 col-sm-8 can-modify"  id="param2" name="param2" value="${paramInfo.param2}" maxlength="20" />
						</div>
					</div>
				</div>
				<%-- <div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="param3"> ${columnNames['param3']}</label>
					<div class="col-sm-9">
						<div class="clearfix">
							<input type="text" class="col-xs-10 col-sm-8 can-modify"  id="param3" name="param3" value="${paramInfo.param3}" maxlength="20" />
						</div>
					</div>
				</div>			
				<div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="param4"> ${columnNames['param4']}</label>
					<div class="col-sm-9">
						<div class="clearfix">
							<input type="text" class="col-xs-10 col-sm-8 can-modify"  id="param4" name="param4" value="${paramInfo.param4}" maxlength="20" />
						</div>
					</div>
				</div>
				<div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="param5"> ${columnNames['param5']}</label>
					<div class="col-sm-9">
						<div class="clearfix">
							<input type="text" class="col-xs-10 col-sm-8 can-modify"  id="param5" name="param5" value="${paramInfo.param5}" maxlength="10" />
						</div>
					</div>
				</div>			
				<div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="param6"> ${columnNames['param6']}</label>
					<div class="col-sm-9">
						<div class="clearfix">
							<input type="text" class="col-xs-10 col-sm-8 can-modify"  id="param6" name="param6" value="${paramInfo.param6}" />
						</div>
					</div>
				</div>
				<div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="param7"> ${columnNames['param7']}</label>
					<div class="col-sm-9">
						<div class="clearfix">
							<input type="text" class="col-xs-10 col-sm-8 can-modify"  id="param7" name="param7" value="${paramInfo.param7}" maxlength="100" />
						</div>
					</div>
				</div>		
				
				<hr />			 --%>
				<%-- <div class="form-group col-xs-12 ">
					<label class="col-sm-3 control-label no-padding-right" for="createUser">修改人员</label>
					<div class="col-sm-9">
						<input type="text" class="col-xs-10 col-sm-8" id="createUser" value="<hw:userName userId='${paramInfo.updateUser}' />" disabled/>
					</div>
				</div>
				<div class="form-group col-xs-12 ">
					<label class="col-sm-3 control-label no-padding-right" for="createTime">修改时间 </label>
					<div class="col-sm-9">
						<input type="text" class="col-xs-10 col-sm-8"  id="createTime" value="${paramInfo.updateTime}" disabled />
					</div>
				</div> --%>
				<%-- <div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="param8"> ${columnNames['param8']}</label>
					<div class="col-sm-9">
						<div class="clearfix">
							<textarea class="form-control limited can-modify col-xs-10 col-sm-8" id="param8" name="param8" >${paramInfo.param8}</textarea>
						</div>
					</div>
				</div> --%>
				<div class="form-group col-xs-12">
					<label class="col-sm-3 control-label no-padding-right" for="remark">备注</label>
					<div class="col-sm-9">
						<div class="clearfix">
							<textarea class="limited form-control can-modify" id="remark" name="remark" >${paramInfo.remark}</textarea>
						</div>
					</div>
				</div>
				
			</div>																					
		</form>
	</div>		
</div>
<script type="text/javascript">
var scripts = [null, null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	
	$("#orgId").orgTreeSelect({
		checkType:"org", 
		clickType:"org",
		defaultOrgId:"${fns:getOrgId()}",
		defaultOrgName:'<hw:orgName orgId="${fns:getOrgId()}" />',
		queryRootOrgId:"${fns:getOrgId()}"
	});
	
	
	$('#param8').inputlimiter({
		//remText: '%n character%s remaining...',
		limit:100,
		remText: '还可用%n 个字符...',
		limitText: '最多字符数 : %n.'
	});
	$('#remark').inputlimiter({
		//remText: '%n character%s remaining...',
		limit:150,
		remText: '还可用%n 个字符...',
		limitText: '最多字符数 : %n.'
	});
	
	initButtons();
	if ("${operFlag}" == "add") {
		$("#orgId").attr("disabled", false);	
		$("#paramKey").attr("disabled", false);			
	} else {
		disabledAll("detailForm");			
	}
	
	$("#detailForm").validate({
	    errorElement: 'div',
	    errorClass: 'help-block',
	    focusInvalid: false,
	    rules: {
	       orgId: {
	          required: false
	       },
	       paramKey: {
	          required: false
	       },
	       param3: {
	    	   required:false,
	    	   stringMaxLength:6
	       },
	       param4: {
	    	   required:false,
	    	   stringMaxLength:6
	       },
	       param5: {
	    	   required:false,
	    	   digits:true,
	    	   stringMaxLength:10
	    	  
	       },
	       param6: {
	    	   required:false,
	    	   number:true,
	    	   stringMaxLength:20
	       },
	       param7: {
	          //number: true
	          required:false,
	          stringMaxLength:30
	       }	       	       
	    },
	
	    /* messages: {
	        orgId: {
	           required: "请输入所属机构"
	        }, 
	        paramKey: {
	           required: "请输入参数主键"
	        } 	        
	    }, */
	
	    highlight: function (e) {
	        $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
	    },
	
	    success: function (e) {
	        $(e).closest('.form-group').removeClass('has-error').addClass('has-info');
	        $(e).remove();
	    }
	});		
});

function initButtons() {
	if ("${operFlag}" == "add") {
		$("#btnPModify").hide();
		$("#btnPSave").show();
		$("#btnPDelete").hide();
		$("#btnPCancle").hide();
		$("#btnPClose").show();		
	} else {
		$("#btnPModify").show();
		$("#btnPSave").hide();
		$("#btnPDelete").show();
		$("#btnPCancle").hide();
		$("#btnPClose").show();	
	}

}


function initParam(){
	if($("#orgId").val()==""){
		$("#orgId").val("*");
	}
	if($("#paramKey").val()==""){
		$("#paramKey").val("*");
	}
}

function save() {
    if ($("#detailForm").valid() == false) {
    	alert("请检查表单是否正确填写");
    	return false;
    }
	enabledAll("detailForm");
	initParam();
	$.ajax({
		async : false,
		url: "${ctx}/parameter/${operFlag}.do",
		type:"post",
		data: $("#detailForm").serialize(),
		dataType:"json",
		success: function(ret){
			if (ret[0] == "ok") {
				alert(ret[1]);
				if ("${operFlag}" == "update") {
					/* initButtons();*/
					disabledAll("detailForm"); 
					showSubList("${paramInfo.paramType}");
					 $("#paraDetailIframe").dialog("close");
				} else {
					$("#paraDetailIframe").dialog("close");
					showSubList("${paramInfo.paramType}");
				}
			} else {
				alert(ret[1]);
				//disabledAll("detailForm");
			}				
		},
		error: function(ret){
			alert(ret.responseText);
			disabledAll("detailForm");
		}
	}); 
}

function modify() {
	$("#btnPModify").hide();
	$("#btnPSave").show();
	$("#btnPDelete").hide();
	$("#btnPCancle").show();
	$("#btnPClose").show();
		
	$("#detailForm .can-modify").attr("disabled", false);	
}

function cancle() {
	if(confirm("是否取消修改？")){
		$("#detailForm")[0].reset();
		initButtons();
		disabledAll("detailForm");
	}
}

function remove() {
	enabledAll("detailForm");
	if(confirm("确认删除吗？")){
	$.ajax({
		async : false,
		url: "${ctx}/parameter/delete.do",
		type:"post",
		data: $("#detailForm").serialize(),
		dataType:"json",
		success: function(ret){	
			if (ret[0] == "ok") {
				alert(ret[1]);
				$("#paraDetailIframe").dialog("close");
				showSubList("${paramInfo.paramType}");
			} else {
				alert(ret[1]);
				disabledAll("detailForm");
			}				
		},
		error: function(ret){
			alert(ret.responseText);
			disabledAll("detailForm");
		}
	});	
	}
	}
</script>
